#!/usr/bin/env python
class Share():
    def __init__(self,id):
        """constructor"""
        self.id = id
        self.name = ""
        self.location = None
        self.automount = False
        self.server = ""
        self.mount_point = ""
        self.options = {}
        self.latency = ""
        self.mounted = False
        
        ### BY BANDOINE POUR SHARE WINDOWS SANS HERITAGE
        self.path = ""
        self.domain = ""
        self.login = ""
        self.password = ""
        self.protocol = ""
        self.port = 80
        ###
        
    def build_option(self,options):
        """
        Output : return the string option
        Dev : Bewiwi
        """
        print options
        option_string = ""
        if len(options) >= 1:
            option_string = " -o "
        for option in options:
            if options[option]==True:
                option_string += option+","
            elif options[option]!=False:
                option_string += option+"="+options[option]+","
            
            
        option_string=option_string.rstrip(",")
        return option_string
    
    def set_default_port(self):
        if self.protocol == 'samba' :
            self.port = 139
        elif self.protocol == 'ftp' :
            self.port = 21
        elif self.protocol == 'ssh' :
            self.port = 22
        elif self.protocol == 'nfs' :
            self.port = 111 # a confirmer
            
    def build_mount_cmd(self):
        return ""
    


### just pour recup build mount cmd    
class SmbShare(Share):
    def __init__(self,id):
        """constructor"""
        Share.__init__(self,id)
        self.login = ""
        self.password = ""
        self.domain = ""
        
    
    def build_mount_cmd(self):
        self.options = {"domain":self.domain,"user":self.login,"password":self.password}
        cmd = "mount.cifs //" + self.server+"/"+self.share+" "+self.mount_point
        cmd+= self.build_option(self.options)
        return cmd
    
class SshShare(Share):
    def __init__(self,id):
        Share.__init__(self,id)
        self.login = ""
        self.password = ""
        self.options = {"password_stdin":True,"allow_other":True}
    
    def build_mount_cmd(self):
        cmd= "sshfs "+self.login+"@"+self.server+":"+self.path+" "+self.mount_point
        cmd+= self.build_option(self.options)
        return cmd
class NfsShare(Share):
    def __init__(self,id):
        Share.__init__(self,id)
        self.path()
    
    def build_mount_cmd(self):
        pass
    
class FtpShare(Share):
    def __init__(self,id):
        Share.__init__(self,id)
        self.login =""
        self.password =""
        self.optionftp={}
        self.optionfuse={}
    
    def build_mount_cmd(self):
        cmd= "curlftpfs  "+self.server+" "+self.path+"-o allow_other -o user=bewiwi:tata"
        cmd+= self.build_option(self.optionfuse)
        cmd+= self.build_option(self.optionftp)
        return cmd
    
    
if __name__ == "__main__" :
    test = FtpShare("nomduserver") 
    test.mount_point = "/media/lyon2/"
    test.server = "baloo.dyndns.org"
    #test.share = "ephemere"
    #test.domain = "esi"
    test.login = "baloo"
    test.password = "prout"
    
    print test.name
    print "sudo "+test.build_mount_cmd()